<?php

$dbc = new PDO('mysql:host=localhost;dbname=Mentor', 'DB Admin', 'MarshyHaka1982');
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

if (isset($_REQUEST['doSave'])) {
    // Fire up your database and do something like
    // INSERT INTO db SET fldSchool = '".addslashes($_REQUEST['School'])."'
    //echo 'testing';
	try {
	    $r = $dbc->Query("INSERT INTO Mentor.usermasterlist SET 
			 FirstName = '".addslashes($_REQUEST['FirstName'])."'
			,LastName = '".addslashes($_REQUEST['LastName'])."'
			,EmailAddress = '".addslashes($_REQUEST['Email Address'])."'
			,Faculty = '".addslashes($_REQUEST['Faculty'])."'
			,School = '".addslashes($_REQUEST['School'])."'
			,ActiveMentor = '".addslashes($_REQUEST['Active Mentor'])."'
			,ReturningMentor = '".addslashes($_REQUEST['Returning Mentor'])."'
			,IndigenousMentor = '".addslashes($_REQUEST['Indigenous Mentor'])."'
			,MentorLeader = '".addslashes($_REQUEST['Mentor Leader'])."'
			,DeputyMentorLeader = '".addslashes($_REQUEST['Deputy Leader'])."'
			,isStaff = '".addslashes($_REQUEST['isStaff'])."'
			,Picture= '".addslashes($_REQUEST['Picture'])."'
		");
	} catch (PDOException $e) {
	    echo "Query failed<br />";
	    echo $e->getMessage();
	    // Crash should exit
	}    if ($_REQUEST['School'] == 'Information Technology') {
        $_REQUEST['School'] = 'Information Technology';
        // or tell user it is an error.
    }
    
    // If all data OK and data inserted into db ok, then maybe go to some other screen? or show this screen with 'success' message and blank stuff out.
    // If user errors, show some kind of message
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>Offline Mentor Database Add Mentor</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <style type="text/css">
  body {
	background-color: #CFF;
}
  </style>
  </head>
<body>
    <pre>
<center><img src="Images/TLD Banner.png" alt="Teaching Learning & Development" /></center>
    </pre>
  
        <form name=AddMentor method="POST" action="PreProcess.php">
		
        <h1 align="center"><strong>Add Mentor Details</strong></h1>
		<table align='center'>
		
		<tr><td>User ID:</td><td><input name="MentorID" type="text" value="" size="35"></td></tr>
        
        <tr><td>First Name</td><td><input name="FirstName" type="text" value="" size="35"></td></tr>
        
        <tr><td>Surname</td><td><input name="Surname" type="text" value="" size="35"></td></tr>
		
		<tr><td>Email</td><td><input name="Email" type="text" value="" size="35"></td></tr>
        
        <tr><td>Faculty</td><td><select name="Faculty"><option value="FAESS">FAESS</option><option value=" FLBCA"> FLBCA</option><option value=" FMHMS"> FMHMS</option><option value=" FSE"> FSE</option></select></td></tr>
		
		<tr><td>School/Discipline</td><td><select name="School"><option value="Arts/Humanities">Arts/Humanities</option><option value="Business">Business</option><option value="Creative Arts/Industries">Creative Arts/Industries</option><option value="Dentistry">Dentistry</option><option value="Education ECE Online">Education ECE Online</option><option value="Education (Primary)">Education (Primary)</option><option value="Education (Secondary)">Education (Secondary)</option><option value="Engineering">Engineering</option><option value="Information Technology">Information Technology</option><option value="Law">Law</option><option value="Nursing">Nursing</option><option value="Pyschology">Pyschology</option><option value="Science">Science</option><option value="Sports &amp; Exercise Science">Sports &amp; Exercise Science</option><option value="Social Science">Social Science</option><option value="Social Work">Social Work</option><option value="Tertiary Access Course">Tertiary Access Course</option></select></td></tr>
        
        <tr><td>Mentor Leader</td><td><select name="Leader"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>Deputy Leader</td><td><select name="Deputy"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>Active Mentor</td><td><select name="Active"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>Returning Mentor</td><td><select name="Returning"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>Indigenous Mentor</td><td><select name="Indigenous"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>Attended<br> Training Day</td><td><select name="Training"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>Attended Welcome Day</td><td><select name="Welcome"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>Collected Reef<br> Trip Ticket</td><td><select name="Reef"><option value="N/A">N/A</option><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
        
        <tr><td>TLD Staff</td><td><select name="Staff"><option value="YES">YES</option><option value="NO">NO</option></select></td></tr>
                        
        <tr><td></td><td><input name="doSubmit" value="Submit" type="submit">
		<input name="doReset" value="Reset" type="reset" /></td></tr>
        </table> 
		<br/><center>&copy; Teaching Learning & Development 2013</center>
        </form>
  </body>
</html>